package com.correo.vista.client.windows.ventanasInternas;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.correo.vista.client.windows.componentes.menu.ItemMenuDinamicos;
import com.correo.vista.client.windows.event.ActionListenerSeleccionTabla;

public class InternalFrameConsultaEnviados extends InternalFrameImpl{

	public static InternalFrameConsultaEnviados internal;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private ItemMenuDinamicos itemMenu;

	public static InternalFrameConsultaEnviados getInstance(){
		if(internal==null){
			internal = new InternalFrameConsultaEnviados();			
		}
		return internal;
	}
	private InternalFrameConsultaEnviados(){
		super("Consulta de Mensajes Enviados",true,true,true,true);		
		createComponents();
		initComponents();
	}
	public ItemMenuDinamicos getItemMenu() {
		return itemMenu;
	}
	public void setItemMenu(ItemMenuDinamicos itemMenu) {
		this.itemMenu = itemMenu;
	}

	/*
	 * Instancio todos los componentes que voy a usar
	 */
	private void createComponents() {
		 jPanel1 = new javax.swing.JPanel();
	        jToolBar1 = new javax.swing.JToolBar();
	        buttonBorrar = new javax.swing.JButton();
	        buttonResponder = new javax.swing.JButton();
	        buttonReenviar = new javax.swing.JButton();
	        jSplitPane1 = new javax.swing.JSplitPane();
	        jPanel2 = new javax.swing.JPanel();
	        jScrollPane1 = new javax.swing.JScrollPane();
	        tableEnviados = new javax.swing.JTable();
	        jPanel3 = new javax.swing.JPanel();
	        jPanel4 = new javax.swing.JPanel();
	        jLabel1 = new javax.swing.JLabel();
	        jLabel2 = new javax.swing.JLabel();
	        lblDe = new javax.swing.JLabel();
	        lblPara = new javax.swing.JLabel();
	        jLabel5 = new javax.swing.JLabel();
	        lblAsunto = new javax.swing.JLabel();
	        jSeparator1 = new javax.swing.JSeparator();
	        jPanel5 = new javax.swing.JPanel();
	        jScrollPane2 = new javax.swing.JScrollPane();
	        jTextPane1 = new javax.swing.JTextPane();
		
	}
	private void initComponents() {
		setActionListener();
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N

        
        buttonBorrar.setText("Borrar"); // NOI18N
        buttonBorrar.setFocusable(false);
        buttonBorrar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonBorrar.setName("jButton1"); // NOI18N
        buttonBorrar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(buttonBorrar);

        buttonResponder.setText("Responder"); // NOI18N
        buttonResponder.setFocusable(false);
        buttonResponder.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonResponder.setName("jButton2"); // NOI18N
        buttonResponder.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(buttonResponder);
        
        
        buttonReenviar.setText("Reenviar"); // NOI18N
        buttonReenviar.setFocusable(false);
        buttonReenviar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        buttonReenviar.setName("jButton3"); // NOI18N
        buttonReenviar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(buttonReenviar);

        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane1.setName("jSplitPane1"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tableEnviados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
               "Enviado a:", "Asunto:", "Fecha:"
            }
        ));
        tableEnviados.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(tableEnviados);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 398, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 280, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
                    .addContainerGap()))
        );

        jSplitPane1.setTopComponent(jPanel2);

        jPanel3.setName("jPanel3"); // NOI18N

        jPanel4.setName("jPanel4"); // NOI18N

        jLabel1.setText(""); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("Enviado a:"); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        lblDe.setText(""); // NOI18N
        lblDe.setName("jLabel3"); // NOI18N

        lblPara.setText(""); // NOI18N
        lblPara.setName("jLabel4"); // NOI18N

        jLabel5.setText("Asunto:"); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        lblAsunto.setText(""); // NOI18N
        lblAsunto.setName("jLabel6"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblPara)
                            .addComponent(lblDe)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblAsunto)
                        .addContainerGap(322, Short.MAX_VALUE))))
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(lblDe))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblPara))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(lblAsunto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel5.setName("jPanel5"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTextPane1.setName("jTextPane1"); // NOI18N
        jScrollPane2.setViewportView(jTextPane1);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 398, Short.MAX_VALUE)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 398, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 99, Short.MAX_VALUE)
            .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jSplitPane1.setRightComponent(jPanel3);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
	}
	
	
	
	private void setActionListener() {
		buttonResponder.addActionListener(new ActionListenerResponder());
		buttonReenviar.addActionListener(new ActionListenerReenviar());
		buttonBorrar.addActionListener(new ActionListenerBorrar());
		tableEnviados.getSelectionModel().addListSelectionListener(new ActionListenerSeleccionTabla(this));
	}



	//variables
	  // Variables declaration - do not modify
    private javax.swing.JButton buttonBorrar;
    private javax.swing.JButton buttonResponder;
    private javax.swing.JButton buttonReenviar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel lblDe;
    private javax.swing.JLabel lblPara;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel lblAsunto;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTable tableEnviados;
    private javax.swing.JTextPane jTextPane1;
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration	


	class ActionListenerResponder implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			//aca tendriamos que abrir la ventana NuevoMensaje 
			//inicializando valores : de, para, y copiarle el mensaje antiguo
			/*
			 * VALIDACION: Validar que se haya seleccionado un item en la tabla.
			 * la idea:
			 * NuevoMensaje.getIntece().inicializarConestosValores(ObejtoConVAlores);
			 * NuevoMensaje.getIntece().setvisible();
			 * 
			 * ObejtoConVAlores: es un objeto que lo creas. apartir de la fila seleccionada.
			 * */
			System.out.println("Respondo el mail");
		}
		
	}
	class ActionListenerReenviar implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			//aca tendriamos que abrir la ventana NuevoMensaje 
			//inicializando valores : de, para, y copiarle el mensaje antiguo
			/*
			 * VALIDACION: Validar que se haya seleccionado un item en la tabla.
			 * la idea:
			 * NuevoMensaje.getIntece().inicializarConestosValores(ObejtoConVAlores);
			 * NuevoMensaje.getIntece().setvisible();
			 * 
			 * ObejtoConVAlores: es un objeto que lo creas. apartir de la fila seleccionada.
			 * */
			System.out.println("Reenvio el mail");
		}
		
	}
	class ActionListenerBorrar implements ActionListener{

		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			/*
			 * Aca tengo que borrar de la base el item que selecionamos.
			 * */
			System.out.println("Se borra un elemento de la tabla");
			int cantidadElegidos =  tableEnviados.getSelectedRows().length;
			if(cantidadElegidos>0){
				for(int i=0;i<cantidadElegidos;i++){
					//((DefaultTableModel)tableRecibidos.getModel()).
				}
			}else{
				//enviar al log
			}
			
		}		
	}
//	
//	class ActionListenerSeleccion implements ListSelectionListener{
//
//		public void valueChanged(ListSelectionEvent e) {
//			// TODO Auto-generated method stub RUDIIIIIIIIIIIIIIIIII
//			/*
//			 * Aca tendria que obtener los datos de una fila y escribirlos en los labels
//			 * y su mensaje correspondiente.
//			 * 
//			 * */
//			System.out.println("Selecciono una fila de la tabla Enviados");
//		}
//		
//	}
//

}
